package purchase.wf;

import org.jbpm.context.exe.ContextInstance;
import org.jbpm.graph.def.ActionHandler;
import org.jbpm.graph.exe.ExecutionContext;

import purchase.util.PurchaseConstants;

/**
 * notify issueperson result
 * 
 * @author Mike 
 *
 */
public class NotifyPurchaseAction implements ActionHandler,PurchaseConstants {

	public void execute(ExecutionContext executionContext) throws Exception {
		ContextInstance contextInstance = executionContext.getContextInstance();
		
		//get manager's advice
		String managerAdvice = (String)contextInstance.getVariable(this.MANAGER_APPROVE_RESULT);
		//get issueperson
		String issueperson = (String)contextInstance.getVariable("issueperson");
		//get manager
		String manager = (String)contextInstance.getVariable("manager");
		String message = "";
		
		//if manager agree purchase
		if (this.MANAGER_APPROVE_RESULT_AGREE.equals(managerAdvice)) {
			message = "Dear "+issueperson+", "+manager+" agrees yours purchase!";
			
		//if manager disagree purchase
		} else if (this.MANAGER_APPROVE_RESULT_DISAGREE.equals(managerAdvice)) {
			message = "Dear "+issueperson+", "+manager+" disagrees yours purchase!";
			
		//issueperson cancel purchase
		} else { 
			message = "Dear "+issueperson+", you have successed to cancel yours purchase!";
		}
		
		System.out.println(message);
	}

}
